<?php
header("Content-type:text/html; charset=utf-8;");
require '../../../ppf/fun.php';
require '../../../ppf/pdo_mysql.php';
require '../../../ppf/Filter.php';
date_default_timezone_set("PRC");
$pd=new pdo_mysql();
$filter=new Filter();
session_start();
if(empty($_SESSION['uid'])){
	echo '请登录后再进行操作';exit;
}
$submitMethod=$_SERVER["REQUEST_METHOD"];
if($submitMethod=='POST'){
    $id      = empty($_POST['id'])?"":$_POST['id'];
	$title =  empty($_POST['title'])?"":$_POST['title'];
	$role =  empty($_POST['role'])?"":$_POST['role'];
	$am_on =  empty($_POST['am_on'])?"":$_POST['am_on'];
	$am_off =  empty($_POST['am_off'])?"":$_POST['am_off'];
	$pm_on =  empty($_POST['pm_on'])?"":$_POST['pm_on'];
	$pm_off =  empty($_POST['pm_off'])?"":$_POST['pm_off'];
	$holiday =  empty($_POST['holiday'])?"":$_POST['holiday'];
	$holiday = implode(',', $holiday);
	if(!$id){
		$in_data=array(
			'title' =>$title,
			'role' =>$role,
			'am_on'  =>$am_on,
			'am_off'  =>$am_off,
			'pm_on'  =>$pm_on,
			'pm_off'  =>$pm_off,
			'holiday'  =>$holiday
	    );
		$rs = $pd->insert(array('data'=>$in_data,'table'=>'sys_rest'));
		if($rs){
			$tips='新建作息表成功';
		}else{
			$tips='新建作息表失败，请重试';
		}
		echo $tips;exit;
	}else{
		$up_data=array(
			'title' =>$title,
			'role' =>$role,
			'am_on'  =>$am_on,
			'am_off'  =>$am_off,
			'pm_on'  =>$pm_on,
			'pm_off'  =>$pm_off,
			'holiday'  =>$holiday
	    );
	    $rg=$pd->update(array('data'=>$up_data,'table'=>'sys_rest','where'=>"id=".$id));
	    if($rg===false){
	    	$tips='更新作息表失败，请重试';	
		}else{
			$tips='更新作息表成功';
		}
		echo $tips;exit;
	}
}else{
	echo '不允许的表单提交方式，请按正常流程提交表单。';exit;
}
?>